/* Given a sequence of length N, such as 2111221, we want to find out a 
 * cut-off point after the k-th character (0 <= k <= N) such that after we 
 * change all digits to the left of the cut-off point to 1 and all digits to
 * the right of the cut-off point to 2, the total number of changes made is 
 * minimized.
 *
 * A simple way to implement this is to check each of the N+1 cut-off points
 * 0, 1, ..., N, and pick the one with the smallest number of changes (i.e.
 * the smallest number of 2s to its left plus number of 1s to its right).
 *
 * This method can be improved to using only one-pass. Suppose we're at the
 * k-th character (1 <= k <= N). For each of the cut-off points 0..k-1 we 
 * have visited, they will need to change all subsequent 1s to 2s. So their
 * additional costs are the same. Therefore the previous optimal cut-off
 * point will remain optimal among all previous points. However, we now have
 * an additional option: to cut-off after the k-th character. The cost is to
 * change all 2s to the left of k to 1s. If this cost is lower than the 
 * previous optimum, we choose this cut-off point as the new optimum.
 */

#include <stdio.h>

int main()
{
    int left2 = 0; /* number of 2s to the left of the current cut-off point */
    int cost = 0;  /* cost of optimal cut-off point */
    int n, i;
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        int digit;
        scanf("%d", &digit);
        if (digit == 2)
            left2++;
        else
            cost++;
        if (left2 < cost)
            cost = left2;
    }
    printf("%d\n", cost);
    return 0;
}
